package edu.wtbu.cs.androiddemo.activity.jump;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import edu.wtbu.cs.androiddemo.R;


/**
 *
 * 商品详情
 */
public class GoodDetailActivity extends AppCompatActivity {

    private TextView tv_title;
    private TextView tv_price;
    private TextView tv_address;
    private TextView tv_counts;
    private TextView tv_content;
    private GoodInfo goodInfo;
    private ImageView im_image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_good_detail);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        goodInfo = (GoodInfo) getIntent().getSerializableExtra("goodinfo");
        String s = getIntent().getStringExtra("key");
        initView();
        initData();
    }

    public void initView(){
        tv_title = (TextView) findViewById(R.id.tv_title_detail);
        tv_price = (TextView) findViewById(R.id.tv_price_detail);
        tv_address = (TextView) findViewById(R.id.tv_addresss);
        tv_counts = (TextView) findViewById(R.id.tv_counts);
        tv_content = (TextView) findViewById(R.id.tv_content);
        im_image = (ImageView) findViewById(R.id.iv_image);
    }

    public  void initData(){
        if (goodInfo != null) {
            im_image.setImageResource(goodInfo.getImge());
            tv_title.setText(goodInfo.getName());
            tv_price.setText("￥:" + goodInfo.getPrice());
            tv_address.setText(goodInfo.getProductLoc());
            tv_counts.setText(goodInfo.getVolume());
            tv_content.setText(goodInfo.getInfo());
        }
    }
}